# -*- coding: UTF-8 -*-
# @IDE     : VScode
# @File   : main.py
# @Time   : 2024/05/23 22:51:03
# @Author : zhonggc

import os
from dotenv import load_dotenv, find_dotenv
from zhipuai import ZhipuAI


def load_env():
    """加载环境变量
    """
    _ = load_dotenv(find_dotenv())


def get_base_completion(question: str, model: str = "glm-4"):
    """基础问答

    Args:
        question (str): 用户的提问内容
    """
    llm = ZhipuAI()
    response = llm.chat.completions.create(
        model=model,  # 填写需要调用的模型名称, 默认为glm-4
        messages=[
            {"role": "system", "content": "你是一个人工智能助手，你叫chatGLM, 你需要在每次回答的最后加上一个`喵`字"},
            {"role": "user", "content": question},
        ],
        stream=True,
    )
    for chunk in response:
        print(chunk.choices[0].delta.content, end="")


if __name__ == "__main__":
    load_env()
    question = "请给电影《肖申克的救赎》做一个简短的影评，1000字左右。"
    get_base_completion(question=question)
